
<html>
<head>
    <title>新增数据源</title>
    <script src="/static/statics/libs/jquery-1.7.2.js"></script>
    <link rel="stylesheet" href="/static/statics/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/statics/plugins/layui/css/layui.css" media="all">
    <script src="/static/statics/plugins/layui/layui.js"></script>
    <script src="/static/statics/plugins/ztree/jquery.ztree.all.min.js"></script>
    <link rel="stylesheet" href="/static/statics/plugins/ztree/css/metroStyle/metroStyle.css">
    <script src="/static/common/js/pageGrid1.js"></script>
    <script src="/static/common/js/selectTool.js"></script>
    <script src="/static/common/js/whole/cyLayer.js"></script>
    <script src="/static/common/js/whole/common.js"></script>
    <script src="/static/common/js/whole/utils.js"></script>
    <script src="/static/common/js/whole/monitor.js"></script>
    <link rel="stylesheet" href="/static/common/css/cyStyle.css">
    <link rel="stylesheet" href="/static/common/css/cyType.css">
</head>
<body>
<div class="layui-field-box">
    <form class="layui-form" action="" id="addFrom">
        <div class="layui-inline">
            <div class="layui-form-item">
            <label class="layui-form-label">数据库类型</label>
            <div class="layui-input-inline">
                <select name="dbtype" lay-verify="required" lay-search=""  lay-filter="dbtype" cyProps="filter:'dbtype'">
                    <option value="ORACLE">ORACLE</option>
                    <option value="MYSQL">MYSQL</option>
                  <!--  <option value="SQLServer2005">SQLServer2005</option>
                    <option value="SQLServer2000">SQLServer2000</option>
                    <option value="POSTGRESQL">POSTGRESQL</option>-->
                </select>
            </div>
                <div class="layui-input-inline">
                    <button class="layui-btn" id="testUrl"><i class="fa fa-undo">&nbsp;</i>测试连接</button>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">连接名</label>
            <div class="layui-input-block">
                <input type="text" name="dbname" id="dbname" lay-verify="title" autocomplete="off" placeholder="请输入数据源名称、昵称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">驱动名称</label>
            <div class="layui-input-block">
                <input type="text" name="driverClass" id="driverClass" lay-verify="required" placeholder="请输入驱动名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">连接地址</label>
            <div class="layui-input-block">
                <input type="text" name="dburl" id="dburl" lay-verify="required" placeholder="请输入JDBC连接地址" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">验证语句</label>
                <div class="layui-input-inline">
                    <input type="text" name="dbtestUrl" id="dbtestUrl" placeholder="请输入验证查询语句"  autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">登录账号</label>
                <div class="layui-input-inline">
                    <input type="text" name="dbaccount" id="dbaccount" placeholder="请输入数据库登录账号" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">登录密码</label>
                <div class="layui-input-inline">
                    <input type="text" name="dbpass" id="dbpass" placeholder="请输入数据库登录密码" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">原始大小</label>
                <div class="layui-input-inline">
                    <input type="text" name="initialSize" id="initialSize" value="10" placeholder="请输入initialSize" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">最大连接数</label>
                <div class="layui-input-inline">
                    <input type="text" name="maxActive" id="maxActive" value="20" placeholder="请输入maxActive" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">最大等待数</label>
                <div class="layui-input-inline">
                    <input type="text" name="maxIdle" id="maxIdle" value="5" placeholder="请输入maxIdle" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">最大等待毫秒</label>
                <div class="layui-input-inline">
                    <input type="text" name="maxWait" id="maxWait" value="200" placeholder="请输入maxWait" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <select name="dbstate" lay-verify="required" lay-search="">
                        <option value="有效">有效</option>
                        <option value="无效">无效</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="page-footer">
            <div class="btn-list">
                <div class="btnlist">
                    <button class="layui-btn"  id="submitData" ><i class="fa fa-floppy-o">&nbsp;</i>保存</button>
                    <button class="layui-btn" onclick="$t.Refresh();"><i class="fa fa-undo">&nbsp;</i>返回</button>
                </div>
            </div>
        </div>
    </form>

</div>

<script>
    layui.use(['form'], function(){
        var form = layui.form;
        $("#submitData").click(function () {
            var indexLod =  Loading.open(2,true);
            var url = "/dbSource/sourceController/addDbSource";
            var params = $('#addFrom').serialize();
            $.ajax({
                type:'POST',
                url:url,
                data:params,
                success:function(data){
                    Loading.close(indexLod);
                    if(data=="新增成功！"){
                        $t.Refresh();
                        Msg.success(data);
                    }else{
                        Msg.error(data);
                    }
                },
                error:function (data) {
                    Loading.close(indexLod);
                    Msg.error(data.responseText);
                }
            });
            return false;
          });
        $("#testUrl").click(function () {
            var url = "/dbSource/testUrl";
            var params = $('#addFrom').serialize();
            $.ajax({
                type:'POST',
                url:url,
                data:params,
                success:function(data){
                    if(data=="连接成功！"){
                        Msg.success(data);
                    }else{
                        Msg.error(data);
                    }
                }
            });
            return false;
        });

        //数据源
         var ORACLE =       {'port':'1521','driverClass':'oracle.jdbc.driver.OracleDriver',
                                'url':'jdbc:oracle:thin:@IP地址:端口号:数据库名称','dbtestUrl':'select 1 from dual'};
         var MYSQL =        {'port':'3306','driverClass':'com.mysql.cj.jdbc.Driver',
                                'url':'jdbc:mysql://IP地址:端口号/数据库名称?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=Asia/Shanghai','dbtestUrl':'select 1 '};
         var SQLServer2005 ={'port':'1433','driverClass':'com.microsoft.sqlserver.jdbc.SQLServerDriver',
                                'url':'jdbc:sqlserver://IP地址:端口号;databasename=数据库名称','dbtestUrl':' select 1'};

         var SQLServer2000 ={'port':'1433','driverClass':'com.microsoft.jdbc.sqlserver.SQLServerDriver',
                                'url':'jdbc:sqlserver://IP地址:端口号;databasename=数据库名称','dbtestUrl':' select 1 '};
         var POSTGRESQL =   {'port':'5432','driverClass':'org.postgresql.Driver',
                                'url':'jdbc:postgresql://IP地址:端口号/数据库名称','dbtestUrl':' select version() '};
        var H2 =       {'port':'1521','driverClass':'oracle.jdbc.driver.OracleDriver',
            'url':'jdbc:oracle:thin:@IP地址:端口号:数据库名称','dbtestUrl':'select 1 from dual'};

        //处理化
        InputInit(ORACLE,"ORACLE");
        //切换
        form.on('select(dbtype)', function (data) {
            var thisValue = data.value;
            var _dbList;
            if(thisValue=="ORACLE"){
                _dbList = ORACLE;

            }else if(thisValue=="MYSQL"){
                _dbList = MYSQL;
            }else if(thisValue=="SQLServer2005"){
                _dbList = SQLServer2005;
            }else if(thisValue=="SQLServer2000"){
                _dbList = SQLServer2000;
            }else if(thisValue=="POSTGRESQL"){
                _dbList = POSTGRESQL;
            }
            InputInit(_dbList,thisValue);
        });
        //处理表单
        function InputInit(_dbList,thisValue){
            $("#dbname").val("WEBSQL-"+thisValue);
            $("#dbport").val(_dbList.port);
            $("#driverClass").val(_dbList.driverClass);
            $("#dburl").val(_dbList.url);
            $("#dbtestUrl").val(_dbList.dbtestUrl);
        }
    });
</script>
</body>
</html>
